#
# Create T-One config file which is saved in $PROTO/etc
#

PROTO							= ~/proto
PROTO_BIN						= $(PROTO)/bin
PROTO_ETC						= $(PROTO)/etc
PROTO_DATA						= $(PROTO)/data
USER							= $(shell id -un)
GROUP							= $(shell id -gn)

TONE_CFG_FILE_TEMPLATE			= docker-compose_offline.yaml
TONE_CFG_FILE_TESTLIB_TEMPLATE	= test-lib_offline.yaml
TONE_CFG_MINI					= minicfg.json
TONE_CFG_FILE					= docker-compose.yaml
TONE_CFG_FILE_WITH_TESTLIB		= docker-compose-with-test-lib.yaml
TONE_CFG_FILE_TESTLIB			= test-lib.yaml
TONE_CFG_FILE_UTIL				= $(PROTO_BIN)/update-tone-config

all: foo

.PHONY: all clean clobber cl install ins uninstall uns

$(TONE_CFG_FILE): $(TONE_CFG_MINI) $(TONE_CFG_FILE_TEMPLATE)
	bash $(TONE_CFG_FILE_UTIL) $^ > $@

$(TONE_CFG_FILE_TESTLIB): $(TONE_CFG_MINI) $(TONE_CFG_FILE_TESTLIB_TEMPLATE)
	bash $(TONE_CFG_FILE_UTIL) $^ > $@

$(TONE_CFG_FILE_WITH_TESTLIB): $(TONE_CFG_FILE) $(TONE_CFG_FILE_TESTLIB)
	cp $< $@
	cat $(TONE_CFG_FILE_TESTLIB) >> $@

foo: $(TONE_CFG_FILE_WITH_TESTLIB)

install: foo
	install -m 0755 -o $(USER) -g $(GROUP) -d $(PROTO_ETC)
	install -m 0555 -o $(USER) -g $(GROUP) $(TONE_CFG_FILE) $(PROTO_ETC)/$(TONE_CFG_FILE)
	install -m 0555 -o $(USER) -g $(GROUP) $(TONE_CFG_FILE_WITH_TESTLIB) $(PROTO_ETC)/$(TONE_CFG_FILE_WITH_TESTLIB)
ins: install

uninstall:
	rm -f $(PROTO_ETC)/$(TONE_CFG_FILE)
	rm -f $(PROTO_ETC)/$(TONE_CFG_FILE_WITH_TESTLIB)
uns: uninstall

clean:

clobber: clean
	rm -f $(TONE_CFG_FILE)
	rm -f $(TONE_CFG_FILE_TESTLIB) $(TONE_CFG_FILE_WITH_TESTLIB)
cl: clobber
